<template>
  <div>
    <v-viewer ref="view"></v-viewer>
    <div class="order-area">
      <div class="customer-area">
        <div class="title">
          <div class="point"></div>
          <span>客户详情</span>
        </div>
        <el-row :gutter="10">
          <el-col :span="3">
            <div class="content-title">
              <span>客户姓名</span>
            </div>
          </el-col>
          <el-col :span="6">
            <span>{{ customer.name }}</span>
          </el-col>
          <el-col :span="3">
            <div class="content-title">
              <span>性别</span>
            </div>
          </el-col>
          <el-col :span="6">
            <span>{{ customer.gender }}</span>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="3">
            <div class="content-title">
              <span>客户手机号</span>
            </div>
          </el-col>
          <el-col :span="6">
            <span>{{ customer.phone }}</span>
          </el-col>
          <el-col :span="3">
            <div class="content-title">
              <span>客户地址</span>
            </div>
          </el-col>
          <el-col :span="6">
            <span>{{ customer.address }}</span>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="3">
            <div class="content-title">
              <span>客户来源</span>
            </div>
          </el-col>
          <el-col :span="6">
            <span>{{ customer.form }}</span>
          </el-col>
          <el-col :span="3">
            <div class="content-title">
              <span>客户邮箱</span>
            </div>
          </el-col>
          <el-col :span="6">
            <span>{{ customer.email }}</span>
          </el-col>
        </el-row>
        <div class="title">
          <div class="point"></div>
          <span>历史提交订单</span>
        </div>
        <el-table ref="multipleTable"
                  border
                  stripe
                  :data="order"
                  style="width: 100%">
          <el-table-column type="expand">
            <template slot-scope="props">
              <el-table :data="props.row.item">
                <el-table-column prop="code"
                                 label="编号">
                </el-table-column>
                <el-table-column prop="productName"
                                 label="货名">
                </el-table-column>
                <el-table-column label="产品图片">
                  <template slot-scope="scope">
                    <pic-view :file-list="scope.row.productUrlList"
                              upload-class="short-upload close-delete"
                              :pic-name-list.sync="scope.row.productNameList"
                              :max-size="scope.row.productUrlList?scope.row.productUrlList.length:0"
                              @showImg="showImg"></pic-view>
                  </template>
                </el-table-column>
                <el-table-column prop="quantity"
                                 label="数量">
                </el-table-column>
                <el-table-column prop="size"
                                 label="长宽高">
                </el-table-column>
                <el-table-column prop="price"
                                 label="单价">
                </el-table-column>
                <el-table-column prop="total"
                                 label="总价">
                </el-table-column>
                <el-table-column prop="productCost"
                                 label="货物成本">
                </el-table-column>
                <el-table-column prop="extraCost"
                                 label="额外成本">
                </el-table-column>
                <el-table-column prop="paymentTime"
                                 label="付款时间">
                </el-table-column>
                <el-table-column prop="goodsFinishTime"
                                 label="货好时间">
                </el-table-column>
                <el-table-column prop="arrivalTime"
                                 label="预计到港时间">
                </el-table-column>
                <el-table-column prop="laidUpTime"
                                 label="入库时间">
                </el-table-column>
                <el-table-column prop="finishedTime"
                                 label="完成时间">
                </el-table-column>
              </el-table>
            </template>
          </el-table-column>
          <el-table-column prop="createdTime"
                           label="创建时间">
          </el-table-column>
          <el-table-column prop="orderNo"
                           label="编号">
          </el-table-column>
          <el-table-column prop="customerName"
                           label="客户名">
          </el-table-column>
          <el-table-column prop="customerTel"
                           label="客户手机号">
          </el-table-column>
          <el-table-column prop="statusName"
                           label="订单状态">
          </el-table-column>
          <el-table-column label="客户合同"
                           width="200">
            <template slot-scope="scope">
              <pic-view :file-list="scope.row.contractUrlList"
                        upload-class="small-upload close-delete"
                        :pic-name-list.sync="scope.row.contractNameList"
                        :max-size="scope.row.contractUrlList?scope.row.contractUrlList.length:0"
                        @showImg="showImg"></pic-view>
            </template>
          </el-table-column>
          <el-table-column label="客户收支证明"
                           width="200">
            <template slot-scope="scope">
              <pic-view :file-list="scope.row.incomeUrlList"
                        upload-class="small-upload close-delete"
                        :pic-name-list.sync="scope.row.incomeNameList"
                        :max-size="scope.row.incomeUrlList?scope.row.incomeUrlList.length:0"
                        @showImg="showImg"></pic-view>
            </template>
          </el-table-column>
          <el-table-column prop="totalAmount"
                           label="总价">
          </el-table-column>
          <el-table-column prop="childOrderAmount"
                           label="总成本">
          </el-table-column>
          <el-table-column prop="sureOrderTime"
                           label="下单时间">
          </el-table-column>
          <el-table-column label="操作"
                           width="80"
                           align="center">
            <template slot-scope="scope">
              <el-button @click="goto(scope.row.id)"
                         type="text"
                         size="small">前往订单</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="foot">
      <el-button type="primary"
                 @click="() => {this.$router.go(-1)}">确定</el-button>
    </div>
  </div>
</template>

<script>
import '@/style/info.scss'
import '@/style/common.scss'
import picView from '@/components/pic-viewer-up'
import vViewer from '@/components/v-viewer'
import { HTTPSUCCESS, HTTPDATAFAIL, HTTPPARAMFAIL, HTTPUNKOWNFAIL } from '@/components/constant'
import { api } from '@/api'
import { packageImgList } from '@/utils/imgPackage'
import { validatenull, vListLength } from '@/utils/validate'

export default {
  data() {
    return {
      customerId: this.$route.params.customerId || null,
      customer: {},
      order: []
    }
  },
  components: {
    picView, vViewer
  },
  activated() {
    this.getCustomerDetail()
  },
  methods: {
    getCustomerDetail() {
      this.$http.get(api.CUSTOMER_DETAIL, { id: this.customerId }).then(
        res => {
          if (res.error.code === HTTPSUCCESS) {
            this.customer = res.result.customer
            this.order = res.result.order
            this.order.forEach(e => {
              if (e.contractPicture) {
                const contractList = packageImgList(e.contractPicture)
                e.contractNameList = contractList[0]
                e.contractUrlList = contractList[1]
              }
              if (e.incomePicture) {
                const contractList = packageImgList(e.incomePicture)
                e.incomeNameList = contractList[0]
                e.incomeUrlList = contractList[1]
              }
              e.item.forEach(ele => {
                if (ele.officialPicture) {
                  const officialList = packageImgList(ele.officialPicture)
                  ele.officialNameList = officialList[0]
                  ele.officialUrlList = officialList[1]
                }
                if (ele.productPicture) {
                  const productList = packageImgList(ele.productPicture)
                  ele.productNameList = productList[0]
                  ele.productUrlList = productList[1]
                }
                if (ele.problemPicture) {
                  const problemList = packageImgList(ele.problemPicture)
                  ele.problemNameList = problemList[0]
                  ele.problemUrlList = problemList[1]
                }
              })
            })
          } else {
            this.$msg._message(res.error.message, 'error')
          }
        }
      )
    },
    goto(id) {
      this.$router.push({
        name: 'order',
        query: {
          orderId: id
        }
      })
    },
    showImg(url) {
      this.$refs.view.showImg(url)
    }
  }
}
</script>

